<template>
  <div class="table-setting">
    <el-form ref="tableSetting"
             :model="setting"
             label-position="top"
             style="height:auto;">
      <el-form-item :label="$t('custom.component.gadget.rowdimension')">
        <el-select v-model="setting.rowDimesion"
                   clearable
                   :placeholder="$t('custom.component.gadget.measureintrowplaceholder')"
                   style="width:80%;">
          <el-option v-for="(item,index) in dataSourceColumns"
                     :key="index"
                     :label="item"
                     :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item  :label="$t('custom.component.gadget.columndimension')">
        <el-select v-model="setting.columnDimesion"
                   style="width:80%;"
                   clearable
                   :placeholder="$t('custom.component.gadget.measureintcolumnplaceholder')">
          <el-option v-for="(item,index) in dataSourceColumns"
                     :key="index"
                     :label="item"
                     :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('custom.component.gadget.measure')">
        <el-select v-model="setting.valueMeasure"
                   style="width:80%;"
                   clearable
                   :placeholder="$t('custom.component.gadget.measurePlaceholder')">
          <el-option v-for="(item,index) in dataSourceColumns"
                     :key="index"
                     :label="item"
                     :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('custom.component.gadget.showpaging')">
        <el-switch v-model="setting.allowPaging"></el-switch>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import Index from '../../dashboard-filter/index.vue'
export default {
  name: 'TableSetting',
  components: { Index },
  data () {
    return {
      dataSource: [],
      dataSourceColumns: [],
      setting: {
        columnDimesion: '',
        rowDimesion: '',
        valueMeasure: '',
        drillThroughStatus: true,
        allowPaging: true,
      },
    }
  },
  props: [
    'data', 'fieldsList'
  ],
  watch: {
    data (value, oldValue) {
      return this.updateSetting(value)
    },
    fieldsList (val) {
      let temp = []
      this.dataSourceColumns = []
      val.forEach(item => {
        temp.push(item.name)
      })
      this.dataSourceColumns = temp
    },
  },
  computed: {
  },
  created () {
    if (this.data) {
      this.$set(this.data)
    }
  },
  methods: {
    getData () {
      return this.setting
    },
    updateSetting (value, list, layerStatus) {
      this._.merge(this.setting, value.gadgetSetting)
      this.$emit('update:data', this.setting)
    }

  }
}
</script>

<style lang="scss">

</style>
